/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#ifndef __R_PUBLIC_H__
#define __R_PUBLIC_H__


// Loads and prepares the given map for rendering
void			R_LoadMap (const char *name);

// Loads and registers the given model
model_t *		R_RegisterModel (const char *name);

// Loads and registers the given material
material_t *	R_RegisterMaterial (const char *name);
material_t *	R_RegisterMaterialLight (const char *name);
material_t *	R_RegisterMaterialNoMip (const char *name);

// Render scenes can be allocated and freed as needed.
// The client will allocate a scene for rendering the game view, but other
// parts of the program can also allocate scenes for other uses, like drawing
// 3D items in the HUD, or displaying models in the GUI.
scene_t *		R_AllocRenderScene (int maxEntities, int maxLights, int maxParticles, int maxDecals);
void			R_FreeRenderScene (scene_t *scene);

// Entities, lights, and particles must be added to a given scene to determine
// what will be drawn for a given view. Most update work is deferred until it
// is determined that it is actually needed for a given view.
// Nothing is drawn until R_RenderScene is called.
int				R_AddRenderEntity (scene_t *scene, const renderEntity_t *renderEntity);
void			R_UpdateRenderEntity (scene_t *scene, int entityHandle, const renderEntity_t *renderEntity);
void			R_FreeRenderEntity (scene_t *scene, int entityHandle);

int				R_AddRenderLight (scene_t *scene, const renderLight_t *renderLight);
void			R_UpdateRenderLight (scene_t *scene, int lightHandle, const renderLight_t *renderLight);
void			R_FreeRenderLight (scene_t *scene, int lightHandle);

int				R_AddRenderParticle (scene_t *scene, const renderParticle_t *renderParticle);
void			R_UpdateRenderParticle (scene_t *scene, int particleHandle, const renderParticle_t *renderParticle);
void			R_FreeRenderParticle (scene_t *scene, int particleHandle);

// Projects a decal onto the world
void			R_ProjectDecalOntoWorld (scene_t *scene, const odVec3 &origin, const odVec3 &direction, float angle, float radius, float time, material_t *material);

// Projects a decal onto the model of the given entity
void			R_ProjectDecal (scene_t *scene, int entityHandle, const odVec3 &origin, const odVec3 &direction, float angle, float radius, float time, material_t *material);

// Removes all decals from the model of the given entity
void			R_RemoveDecals (scene_t *scene, int entityHandle);

// Compiles all lights, generating lists of static interactions and shadows.
// If this isn't called after loading a map, all world interactions and shadows
// will be dynamically generated.
void			R_CompileLights (scene_t *scene);

// Rendering a scene may actually render multiple views for mirrors, portals,
// remote cameras, and portal skies.
// If primaryView is false, the world map will be ignored completely, which is
// useful for rendering things like GUI models.
void			R_RenderScene (scene_t *scene, const renderView_t *renderView, bool primaryView);

// 2D drawing just involves material parameter setting and axial image
// subsections
void			R_SetColor (const odVec4 &color);
void			R_SetColor4 (float r, float g, float b, float a);

void			R_DrawStretchPic (float x, float y, float w, float h, float s1, float t1, float s2, float t2, material_t *material);
void			R_DrawShearedPic (float x, float y, float w, float h, float s1, float t1, float s2, float t2, float xShear, float yShear, material_t *material);

// To render to a texture, first set the crop size, then perform all desired
// rendering, then capture to a texture.
// The width and height values are in virtual 640x480 coordinates.
// Users of the renderer will not know the actual pixel size of the area they
// are rendering to.
// If the specified physical dimensions are larger than the current cropped
// region, they will be cut down to fit.
void			R_CropRenderSize (int width, int height, bool makePowerOfTwo);
void			R_UnCrop (void);

// Captures the screen render to the given texture.
// Returns false if the texture wasn't found or couldn't be dynamically
// modified.
bool			R_CaptureRenderToTexture (const char *name);

// Updates the given texture's image. The image data must be in RGBA format,
// and the size must be a power of two.
// Returns false if the texture wasn't found or couldn't be dynamically
// modified.
bool			R_UpdateTextureImage (const char *name, const byte *image, int width, int height);

// Draws a box representing an editable entity (for integrated editors)
void			R_DrawEditBox (const odVec3 &color, const odVec3 corners[8]);

// A frame can consist of 2D drawing and potentially multiple 3D scenes
void			R_BeginFrame (int frameTime);
void			R_EndFrame (void);

// Enumerates material scripts using a callback.
// This is for use by integrated editors.
void			R_EnumMaterialScripts (void (*callback)(const char *));

// Allows other subsystems to get the current GL configuration
void			R_GetGLConfig (glConfig_t *config);

// Initializes the renderer subsystem.
// If all is false, the OpenGL subsystem will not be initialized, which is
// useful for flushing all data and resetting the state.
void			R_Init (bool all);

// Shuts down the renderer subsystem.
// If all is false, the OpenGL subsystem will not be shut down, which is useful
// for flushing all data and resetting the state.
void			R_Shutdown (bool all);


#endif	// __R_PUBLIC_H__
